package day5

case class Teacher (name:String,sex:Int)

object Test4 {
  def main(args: Array[String]): Unit = {
    val list = List(Teacher("王兄",1),Teacher("李兄",1),Teacher("王妹",2)
                                    ,Teacher("小赵",1),Teacher("扶气",1),Teacher("小红",2))

    // 统计出男女老师的个数    男 4    女 2

    val map: Map[String, List[Teacher]] = list.groupBy(v => if (v.sex == 1) "男" else "女")
    map.foreach(v => {
//      println(v._1 + "\t" + v._2.size )  新方法
      var sum = 0
      for (elem <- v._2) {
        sum += 1
//        println(elem)
      }
      println(v._1 + "\t" + sum)
    })

  }
}
